package com.authorization.authorizationserveronsso.controller;


import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author ：hyq
 * @date ：Created in 2021/4/14 10:59
 * @description：
 * @modified By：
 */
@RestController
@RequestMapping
@Api(value="测试api登录接口",description="测试api登录接口")
public class LoginApiController {

//    @Autowired
//    private SysLoginService loginService;
//    @Autowired
//    private TokenService tokenService;

    @Autowired
    private TokenStore tokenStore;


//    @ApiOperation("登录")
//    @GetMapping("/login2")
//    public DataBus login(String username, String pwd){
//        String token = loginService.login(username,pwd);
//        return DataBus.success().data("200",token);
//    }
//    @ApiOperation("jwt")
//    @PostMapping("/jwt")
//    public DataBus test(HttpServletRequest request){
//        //获取当前登录信息
//        LoginUser loginUser = tokenService.getLoginUser(request);
//        return DataBus.success().data("200",loginUser.getUser());
//    }

    /**
     * 认证页面
     *
     * @return ModelAndView
     */
    @GetMapping("/hello")
    public ModelAndView require() {
        return new ModelAndView("/login");
    }


//    @GetMapping("/login")
//    public String hello() {
//        //这边我们,默认是返到templates下的login.html
//        return "login";
//    }

    @RequestMapping("/success")
    public String success() {
        return "login success";
    }




    /**
     * 令牌管理调用
     *
     * @param token token
     * @return
     */
    @RequestMapping("/deltoken")
    public String delToken(String token) {
        OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(token);
        tokenStore.removeAccessToken(oAuth2AccessToken);
        return "token 已清除";
    }

}
